//
//  StatusCellTop.swift
//  weibo1990
//
//  Created by 曹晓龙 on 15/10/19.
//  Copyright © 2015年 曹晓龙. All rights reserved.
//

import UIKit



class StatusCellTop: UIView {

    /// 单条微博数据视图模型
    var statusViewModel:StatusViewModel?{
        
        didSet{
            
            iconView.sd_setImageWithURL(statusViewModel?.iconViewUrl, placeholderImage: statusViewModel?.holderImage)
            nameLbl.text = statusViewModel?.status.user?.screen_name
            memberIcon.image = statusViewModel?.memberImage
            
            let timeText = NSDate.getDateWithString(statusViewModel?.status.created_at ?? "")?.dateDescription
            timeLbl.text = timeText
            
            sourceLbl.text = statusViewModel?.status.source
            
            vipIcon.image = statusViewModel?.vipIconImage
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var iconView:UIImageView = UIImageView(imageName: "avatar_default_big")
    lazy var nameLbl:UILabel = UILabel(titleText: "发布人", textFont: 15)
    lazy var memberIcon:UIImageView = UIImageView(imageName: "common_icon_membership_level2")
    lazy var timeLbl:UILabel = UILabel(titleText: "刚刚", textFont: 11, color: UIColor.orangeColor())
    lazy var sourceLbl:UILabel = UILabel(titleText: "来源", textFont: 11)
    lazy var vipIcon:UIImageView = UIImageView(imageName: "avatar_vip")
}

// MARK: - 设置UI
extension StatusCellTop {
    
    private func setupUI(){
        
        // 添加控键
        addSubview(iconView)
        addSubview(nameLbl)
        addSubview(memberIcon)
        addSubview(timeLbl)
        addSubview(sourceLbl)
        addSubview(vipIcon)
        
        //自动布局
        
        //头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(statusCellMargin)
            make.top.equalTo(self.snp_top).offset(statusCellMargin)
            make.width.equalTo(statusCellIconWidth)
            make.height.equalTo(statusCellIconWidth)
        }
        //name
        nameLbl.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.top.equalTo(iconView.snp_top)
        }
        // 会员
        memberIcon.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLbl.snp_right).offset(statusCellMargin)
            make.top.equalTo(nameLbl.snp_top)
        }
        // 发布时间
        timeLbl.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        // 来源
        sourceLbl.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLbl.snp_right).offset(statusCellMargin)
            make.bottom.equalTo(timeLbl.snp_bottom)
        }
        // vip
        vipIcon.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }

        
    }
    
}